package com.shujia.MR.mapjoin;

import com.shujia.MR.wordcount.MyWordCountDriver;
import com.shujia.MR.wordcount.MyWordCountReducer;
import com.shujia.MR.wordcount.MyWrodCountMapper;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;


/**
 * 需求：
 *      针对学生成绩表中的科目ID关联科目信息
 */
public class MapJoinDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException, URISyntaxException {
        Configuration conf = new Configuration();
        // 创建一个Job
        Job job = Job.getInstance(conf);

        job.setJarByClass(MapJoinDriver.class);
        job.setJobName("MapJoin");

        // 设置Mapper及Reducer类
        job.setMapperClass(MapJoinMapper.class);

        // 设置Map方法输出类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);

        // 设置最终输出类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);

        //
//        job.addCacheFile(new URI("file://D:\\workspace19\\HadoopCode"));
        job.addCacheFile(new Path("D:\\workspace19\\HadoopCode\\data\\mapjoin\\subject.txt").toUri());

        // 设置数据源以及输出结果,注意选择 org.apache.hadoop.mapreduce.lib.input.FileInputFormat
        FileInputFormat.addInputPath(job, new Path("D:\\workspace19\\HadoopCode\\data\\count"));
        FileOutputFormat.setOutputPath(job, new Path("D:\\workspace19\\HadoopCode\\output\\mapjoin"));

        // 提交
        job.waitForCompletion(true);
    }
}
